package 每日一题;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 会玩的洋洋
 * https://leetcode.cn/problems/decode-the-message/
 */
public class _2325_解密消息 {
    /**
     * 执行用时：5ms，内存消耗：41.4MB
     * @param key
     * @param message
     * @return
     */
    public String decodeMessage(String key, String message) {
        Map<Character, Character> cache = new HashMap<>();
        int n = key.length();
        char num = 'a';
        cache.put(' ', ' ');
        for (int i = 0; i < n; i++) {
            char c = key.charAt(i);
            if (cache.containsKey(c)) {
                continue;
            }
            cache.put(c, num);
            num = (char) (num + 1);
        }

        int m = message.length();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < m; i++) {
            char c = message.charAt(i);
            sb.append(cache.get(c));
        }
        return sb.toString();
    }
}
